/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package engine;

/**
 *
 * @author Yole
 */
import java.awt.event.MouseMotionListener;
import java.awt.event.MouseEvent;
import graphics.player.SpaceShip;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.lang.Math;

public class MouseControls implements MouseMotionListener {

    SpaceShip sship;

    public MouseControls( SpaceShip sship ) {

        this.sship = sship;

    }
    public synchronized void mouseMoved( MouseEvent event ) {

        int posx = sship.getPos()[0];
        int posy = sship.getPos()[1];
        int xTarget = event.getX()-sship.getWidth()/2;
        int yTarget = event.getY()-sship.getHeight()/2;
        double distance = Math.sqrt( Math.pow(xTarget, 2) + Math.pow(yTarget, 2));
       
        //while ( posx != xTarget && posy != yTarget ) {

            try {
                Thread.sleep(100);
            } catch (InterruptedException ex) {
                Logger.getLogger(MouseControls.class.getName()).log(Level.SEVERE, null, ex);
            }
            /*
            if ( posx < xTarget ) posx += 5*xTarget/(int)distance;
            else posx -= 5*xTarget/(int)distance;
            if ( posy < yTarget ) posy += 5*yTarget/(int)distance;
            else posy -= 5*yTarget/(int)distance;
            System.out.println( "x: " + posx + "y: " + posy + "xex: " + xTarget + "yex: " + yTarget );*/
            sship.setPos( xTarget, yTarget );

        //}
    }

    public void mouseDragged(MouseEvent e) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

}
